﻿#pragma once

#include "common.h"

namespace cv
{
	class VideoCapture;
	class Mat;
}

namespace anip
{
	class Texture2D;

	class VideoProvider
	{
	private:
		cv::VideoCapture* _cap;
		cv::Mat* _mat, * _flipped;
		bool _end = false;
		Texture2D* _tex;

		VideoProvider(cv::VideoCapture& cap);

	public:
		~VideoProvider();

		static VideoProvider* fromFile(const string& path);
		static VideoProvider* fromDevice(int i = 0);
		bool nextFrame();
		
		const Texture2D& getTexture() const { return *_tex; }
		bool atEnd() const { return _end; }

		void setFramePosition(int n);
		int framePosition() const;

		vec2 size() const;
		double frameRate() const;
	};
}